package com.zs.helper;

import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class DownLoadHelper implements Cloneable {
	private final static String FILE_NAME = "/Users/zhangshuqing/home/hello.mp3";

	private FileChannel mChannel;

	private ByteBuffer buffer;
	private String flag;

	@SuppressWarnings("resource")
	public DownLoadHelper() {
		try {
			buffer = ByteBuffer.allocate(1024);
			mChannel = new FileInputStream(FILE_NAME).getChannel();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public int read() throws IOException {
		buffer.clear();
		int len = mChannel.read(buffer);
		buffer.flip();
		return len;
	}

	public void close() throws IOException {
		if(mChannel!=null){
			mChannel.close();
		}
		
	}

	public String getFlag() {
		return flag;
	}

	public void setFlag(String flag) {
		this.flag = flag;
	}

	public ByteBuffer getBuffer() {
		return buffer;
	}

}
